package example.service;

import example.dao.connect;
import org.json.JSONException;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ware_c {

    public static String ware_get(String username) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet p = stmt.executeQuery("select * from goods where saleman = '"+username+"' and state = '1'");
        return jsonzhuan.resultSetToJson(p);
    }

    public static String sware_get(String username) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet p = stmt.executeQuery("select * from goods g , sale s where s.goodsid = g.goodsid and g.saleman = '"+username+"'");
        return jsonzhuan.resultSetToJson(p);
    }

    public static String dware_get(String username) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet p = stmt.executeQuery("select * from goods where saleman   = '"+username+"' and state = '2'");
        return jsonzhuan.resultSetToJson(p);
    }

    public static void ware_d(String ID) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        String sql = "update goods set state = '2' where ID = '"+ID+"'";
        Statement stmt=conn.createStatement();//创建一个Statement对象
        stmt.executeUpdate(sql);//执行sql语句
    }

    public static void ware_back(String ID) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        String sql = "update goods set state = '1' where ID = '"+ID+"'";
        Statement stmt=conn.createStatement();//创建一个Statement对象
        stmt.executeUpdate(sql);//执行sql语句
    }

    public static void ware_change(String ID , String biaoti , String price , String number) throws SQLException, JSONException {
        Connection conn = connect.getConnection();
        String sql = "update goods set biaoti = '"+biaoti+"' , price = '"+price+"' , number = '"+number+"' where ID = '"+ID+"'";
        Statement stmt=conn.createStatement();//创建一个Statement对象
        stmt.executeUpdate(sql);//执行sql语句
    }

}
